home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
choices
/
chcssml1.lha
/
SoftwareException.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-06
|
3KB
|
93 lines
/*
* This file is part of the Choices Operating System Simulator
* Developed by: The TAPESTRY Parallel Computing Laboratory
* University of Illinois at Urbana-Champaign
* Department of Computer Science
* 1304 W. Springfield Ave.
* Urbana, IL 61801
*
* Copyright (c) 1987, 1988, 1989 The University of Illinois Board of Trustees.
* All Rights Reserved.
* CONFIDENTIAL INFORMATION. Distribution restricted under license agreement.
*
* Author: Gary M. Johnston (johnston@cs.uiuc.edu)
* Project Manager and Principal Investigator: Roy Campbell (roy@cs.uiuc.edu)
*
* Funded by: NSF TAPESTRY Grant No. 1-5-30035, NASA ICLASS Grant
* No. 1-5-25469 and No. NSG1471 and AT&T Metronet Grant No. 1-5-37411.
*/
/*
* SoftwareException.c - Implementations of classes SoftwareException and
* SemaphoreException.
*
* $Header$
* $Locker$
*/
#include "Assert.h"
#include "Debug.h"
#include "Process.h"
#include "CPU.h"
#include "Clock.h"
#include "Name.h"
#include "Exception.h"
#include "SoftwareException.h"
#include "ProcessContainer.h"
SoftwareException::SoftwareException(char * name):
(name ? name : MakeName( "SoftwareException", this) )
{
}
void SoftwareException::raise()
{
Debug("%s::raise(%s).\n", getName(), ThisCPU()->getName());
ThisCPU()->trap(this);
Debug("%s::raise(%s) return.\n", getName(), ThisCPU()->getName());
}
void
SoftwareException::handle(CPU * cpu, int vector)
{
Debug( "%s::handle(%s).\n", getName(), cpu->getName());
}
SemaphoreException::SemaphoreException(char * name, Semaphore * s ):
(name ? name : MakeName( "SemaphoreException", this) )
{
saveSemaphore = s; //This is the semaphore that is being served.
}
void
SemaphoreException::handle(CPU * cpu, int vector)
{ //Interrupts are off, and this is a critical section.
Debug( "%s::handle(%s).\n", getName(), cpu->getName());
Assert(cpu != 0);
Process * current = cpu->remove();
Assert( current != 0 );
Assert( current != cpu->idleProcess );
/*
* Remove the current process from the processor.
* Try to remove a Process from the CPU's scheduler.
* Dispatch the new Process or the IdleProcess.
* Save the process on the saveQ. Be sure
* to never enqueue the idle process anywhere.
*/
Assert( saveSemaphore != 0 );
saveSemaphore->queue->add( current ); //Put process on semaphore queue.
Debug( "SoftwareException::handle: enqueued %A\n",
current );
ProcessContainer * scheduler = cpu->scheduler;
Assert( scheduler != 0 );
Process * newProcess = scheduler->remove(); //Get another process
if( newProcess == 0 ) newProcess = cpu->idleProcess;
Assert( newProcess != 0 );
Debug("%s::handle:add %s to %s.\n",
getName(), newProcess->getName(), cpu->getName());
saveSemaphore->locked = 0; //Reset Semaphore lock to exit critical sect.
cpu->add( newProcess ); //Run process on CPU
}